1. Field of the Invention
This invention relates to a method and an apparatus for coding image data.
2. Description of the Prior Art
A highly efficient coding system for compressing a data amount is used in various apparatuses such as a communication apparatus, a recording and reproducing apparatus, a VCR, a VTR, and a display apparatus. Some of such coding systems use a code having variable-length words. Generally, it is desirable that coded data is outputted from a coding system at essentially a constant bit rate.
A system using orthogonal transform and a variable-length code is effective in efficiently coding data of natural images. It has been decided that this system is adopted in the international standards of coding of color natural image data (ISO/IEC JTC 1/SC2/WG8: JPEG Technical Specification, JPEG-8-R5, Jan. 2, 1990). Since this system uses the variable-length code, the amount (the number of bits) of coded output data tends to vary image by image. It should be noted that the code length of output data is a general term meaning the amount of coded output data.
Generally, an image data recording apparatus such as a VTR or a VCR is designed to record data at essentially a constant bit rate. To realize the recording of data at essentially a constant bit rate, it is necessary to control the amount of coded output data from a coding section image by image. Accordingly, systems for controlling the amount of coded data have been proposed (for example, ITEC '92:1992 ITE Annual Convention 16-15 "Bit-rate Control for the JPEG Coding").
In image data coding, it is general that every frame or field of image data is divided into a predetermined number of portions called blocks, and the image data is processed block by block.
In the system disclosed in the documents ITEC '92, during a first pre-scanning process, some blocks are selected from blocks composing one frame, and data in the selected blocks is quantized and coded with a first scale factor (a first scaling factor). In addition, the code amount in one frame is estimated from the mount of the coded data in the selected blocks, and a second scale factor (a second scaling factor) is set in response to a difference between the estimated code amount and a target code amount in one frame. During a second pre-scanning process following the first pre-scanning process, some blocks are selected from the blocks composing one frame, and data in the selected blocks is quantized and coded with the second scale factor. In addition, the code amount in one frame is estimated from the amount of the coded data in the selected blocks, and a third scale factor (a third scaling factor) is set in response to a difference between the estimated code amount and the target code amount in one frame and also in response to the second scale factor. Such a pre-scanning process is periodically repeated until a difference between the estimated code amount and the target code amount in one frame falls into an allowable range. The final scale factor obtained in the pre-scanning processes is used in a main scanning process for actually quantizing and coding data in all the blocks composing one frame.
In the system disclosed in the documents ITEC '92, the actually-used scale factor is thus updated every frame. Accordingly, during every main scanning process corresponding to one frame, the actually-used scale factor remains unchanged. In some cases, there occurs a large error between an actual code amount and the target code amount due to keeping the actually-used scale factor unchanged during one frame. The large error in one direction means that the actual code amount excessively overflows from the target code amount. When such an overflow occurs in a VTR or a VCR, an end portion of image data can not be recorded.